package com.bupt.godxian.charging.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bupt.godxian.charging.entity.Charger;
import com.bupt.godxian.charging.entity.WaitArea;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.math.BigDecimal;
import java.util.List;

@Mapper
public interface ChargerMapper extends BaseMapper<Charger> {
    @Select("SELECT * FROM charger ORDER BY id ASC")
    List<Charger> findAllorder();

    @Select("SELECT cumulative_usage_times FROM charger WHERE id = #{id}")
    Double selectCumulativeUsageTimes(@Param("id") Long id);

    @Update("UPDATE charger SET cumulative_usage_times = #{cumulativeUsageTimes} WHERE id = #{id}")
    void updateCumulativeUsageTimes(@Param("id") Long id, @Param("cumulativeUsageTimes") Double cumulativeUsageTimes);

    @Select("SELECT cumulative_charging_time FROM charger WHERE id = #{id}")
    Integer selectCumulativeChargingTime(@Param("id") Long id);

    @Update("UPDATE charger SET cumulative_charging_time = #{cumulativeChargingTime} WHERE id = #{id}")
    void updateCumulativeChargingTime(@Param("id") Long id, @Param("cumulativeChargingTime") Integer cumulativeChargingTime);

    @Select("SELECT cumulative_charging_amount FROM charger WHERE id = #{id}")
    String selectCumulativeChargingAmount(@Param("id") Long id);

    @Update("UPDATE charger SET cumulative_charging_amount = #{cumulativeChargingAmount} WHERE id = #{id}")
    void updateCumulativeChargingAmount(@Param("id") Long id, @Param("cumulativeChargingAmount") String cumulativeChargingAmount);

    @Update("UPDATE charger SET cumulative_charging_time = #{cumulative_charging_time} WHERE id = #{chargePileId}")
    void updateCumulativeChargingTime(String chargePileId,@Param("cumulative_charging_time")BigDecimal cumulative_charging_time);

    @Select("SELECT * FROM charger WHERE id = #{pile_id} LIMIT 1")
    Charger selectOnebyId(String pile_id);

    //更新 Charger 记录的累计充电时间、累计充电金额和累计使用次数
    @Update("UPDATE charger\n" +
            "SET cumulative_usage_times = cumulative_usage_times + 1,\n" +
            "    cumulative_charging_time = cumulative_charging_time + #{chargedTime},\n" +
            "    cumulative_charging_amount = cumulative_charging_amount + #{chargedAmount}\n" +
            "WHERE id = #{pileId} LIMIT 1;")
    void updatecharger(long chargedTime, double chargedAmount, String pileId);


}


